package com.mf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mf.entity.DayLog;
import com.mf.mapper.DayLogMapper;
import com.mf.service.IDayLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mf.vo.DayLog.DayLogPageVo;
import io.micrometer.common.util.StringUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import javax.lang.model.element.QualifiedNameable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mf
 * @since 2024-05-17
 */
@Service
public class DayLogServiceImpl extends ServiceImpl<DayLogMapper, DayLog> implements IDayLogService {
    @Resource
    private DayLogMapper dayLogMapper;

    @Override
    public Page<DayLog> findDayLogPage(DayLogPageVo dayLogPage) {
        final LambdaQueryWrapper<DayLog> queryWrapper = new LambdaQueryWrapper<>();

        // 时间范围
        if (StringUtils.isNotEmpty(dayLogPage.getStart()) && StringUtils.isNotEmpty(dayLogPage.getEnd())) {
            queryWrapper.between(DayLog::getDate, dayLogPage.getStart(), dayLogPage.getEnd());
        }
        if(StringUtils.isNotEmpty(dayLogPage.getType())){
            queryWrapper.eq(DayLog::getType, dayLogPage.getType());
        }
        queryWrapper.orderByDesc(DayLog::getUpdateTime);
        Page<DayLog> page = new Page<>(dayLogPage.getPageNum(), dayLogPage.getPageSize());
        return dayLogMapper.selectPage(page, queryWrapper);
    }
}
